﻿@using Nop.Core.Infrastructure;
@{
    var electronicsThemeSettings = EngineContext.Current.Resolve<SevenSpikes.Theme.Electronics.Domain.ElectronicsThemePluginsIntegrationSettings>();
    var instantSearchIntegrated = electronicsThemeSettings.IntegrateNopInstantSearch;
}
@using (Html.BeginRouteForm("ProductSearch", FormMethod.Get, new { onsubmit = "return check_small_search_form()" }))
{   
    <div class="searchboxtext">
        <input type="text" id="small-searchterms" class="search_tx" value="@T("SevenSpikes.Themes.Electronics.Common.SearchStoreText")" name="q"  
            onfocus="if(this.value=='@T("SevenSpikes.Themes.Electronics.Common.SearchStoreText")')this.value=''" onblur="if(this.value=='')this.value='@T("SevenSpikes.Themes.Electronics.Common.SearchStoreText")'" />
    </div>
    <div class="searchboxbutton">
        <input type="submit" class="searchButtonClass" id="btn-small-search" value="@T("Search")" name="btnSearch" @(Model.AutoCompleteEnabled ? Html.Raw(" autocomplete=\"off\"") : null) />
    </div>
    <script type="text/javascript">

            function check_small_search_form() {
                var search_terms = $("#small-searchterms");
                if (search_terms.val() == "") {
                    alert('@T("Search.EnterSearchTerms")');
                    search_terms.focus();
                    return false;
                }

                return true;
            }
            @if (Model.AutoCompleteEnabled && !instantSearchIntegrated)
            {
                <text>
                $(function () {
                    $('#small-searchterms').autocomplete({
                        delay: 500,
                        minLength: @(Model.SearchTermMinimumLength.ToString()),
                        source: '@(Url.RouteUrl("ProductSearchAutoComplete"))',
			            select: function( event, ui ) {
				            $("#small-searchterms").val(ui.item.label);
                            setLocation(ui.item.producturl);
				            return false;
			            }
                    })
                    .data("autocomplete")._renderItem = function( ul, item ) {
                    var t = item.label;
                    //html encode
                    t = htmlEncode(t);
                    return $("<li></li>")
                    .data("item.autocomplete", item)
                    .append("<a>@(Model.ShowProductImagesInSearchAutoComplete ? Html.Raw("<img src='\" + item.productpictureurl + \"'>") : null)" + t + "</a>")
                    .appendTo(ul);
                    };
                });
                </text>
            }
        </script>  
    
    @Html.Action("WidgetsByZone", "Widget", new { widgetZone = "searchbox" })
}
@if (instantSearchIntegrated)
{
    @Html.Action("InstantSearch", "InstantSearch")
}